//
//  DHAlert.m
//  NavigationDemo
//
//  Created by 商广硕 on 2022/7/17.
//

#import "DHAlert.h"

@implementation DHAlert

- (instancetype)init{
    if (self = [super init]) {
        [self customAlert];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self customAlert];
    }
    
   
    
    return self;
}

-(void)customAlert{
    CGFloat QCWidth = [UIScreen mainScreen].bounds.size.width;
      CGFloat QCHeight = [UIScreen mainScreen].bounds.size.height;
      CGFloat offset = 50;//弹出框两边边距
      CGFloat width = QCWidth -offset*2;//弹出框宽
      CGFloat height = 300;//弹出框高
    
    //背景图
        UIView * backview = [[UIView alloc]initWithFrame:CGRectMake(0, -64, QCWidth, QCHeight+64)];
        backview.backgroundColor = [[UIColor clearColor]colorWithAlphaComponent:0.5f];
    
    
    //显示弹窗视图
      UIView *view = [[UIView alloc]initWithFrame:CGRectMake(offset,(QCHeight-height)/2,width,height)];
      view.backgroundColor =[UIColor whiteColor];
    view.layer.cornerRadius = 8;
    [backview addSubview:view];
    
    [self addSubview:backview];

    UILabel *egLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, width, 13)];
      [view addSubview:egLabel];
      egLabel.font = [UIFont systemFontOfSize:13];
//      egLabel.textColor = RGBA(32, 169, 242, 1);
      egLabel.textAlignment = NSTextAlignmentCenter;
      egLabel.text = @"以下为自定义部分， 确认取消按钮可以删除哦";
    
    [view addSubview:egLabel];
    //取消按钮
    UIButton *btn= [UIButton buttonWithType:UIButtonTypeCustom];
   
  
    btn.frame = CGRectMake(0, height - 35, width/2, 35);
    btn.backgroundColor= [UIColor blueColor];
//    btn.titleLabel.font = [UIFont systemFontOfSize:14];
//    [ self.cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
//    [ self.cancelBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [ btn addTarget:self action:@selector(onCancle) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview: btn];
    
}

+ (instancetype)showAlert:(NSString *)text Cancle:(CancleBlock)cancle {
    DHAlert * alert =[[DHAlert alloc] init];
    alert.cancleBlock = cancle;
//    [[[UIApplication sharedApplication] windows].firstObject addSubview:alert];
    return alert;
}
-(void)onCancle{
    NSLog(@"----------");
//    [self.bgView removeFromSuperview];
//        [self removeFromSuperview];
//        self.hidden = YES;
//    self.cancleBlock();
}
@end
